<template lang="html">
  <div class="user_page">
    <Swipe v-if="page_type !== 'join_vip'"></Swipe>
    <div class="page_bg">
      <div class="join_vip_user" v-if="page_type === 'join_vip'">
        <img class="user_img" v-bind:src="invite_info.user_avatar"/>
        <div class="join_info">
          <div class="user_name">Hi，我是{{invite_info.user_nickname}}</div>
          <div class="tips">分享一个正品购物平台给你</div>
        </div>
      </div>
    </div>
    <div class="vip_privilege">
      <!-- <div class="equity_bg"></div> -->
      <div class="vip_privilege_pack">
        <div class="buy_purchase">
          <van-swipe :autoplay="3000" :vertical="true" :show-indicators="false" :width="300" :height="72" :touchable="false">
            <van-swipe-item v-for="(item, k) in mit_tips" v-bind:key="k">
              <div class="tips_txt">{{item}}</div>
            </van-swipe-item>
          </van-swipe>
        </div>
        <div class="buy_purchase share_tips">
          <van-swipe :autoplay="3000" :vertical="true" :show-indicators="false" :width="300" :height="72" :touchable="false">
            <van-swipe-item v-for="(item, k) in share_tips" v-bind:key="k">
              <div class="tips_txt">{{item}}</div>
            </van-swipe-item>
          </van-swipe>
        </div>
      </div>
      <div class="vip_title"></div>
    </div>
    <div class="prd_list">
      <div class="list">
        <PrdItem v-for="(item, key) in prd_list" :item="item" v-bind:key="key"></PrdItem>
      </div>
    </div>
    <van-popup v-model="first_show" :close-on-click-overlay="false">
      <div class="buy_diago">
        <h3>提示</h3>
        <div class="diago_content">
          若购买该礼包，您将放弃<br/>本次推荐返利及领取机会
        </div>
        <div class="action_btn">
          <span @click="closeTips">重新选择</span>
          <span class="cannle_btn" @click="againOpenTips">继续购买</span>
        </div>
      </div>
    </van-popup>
    <div class="again_box">
      <van-popup v-model="last_show" :close-on-click-overlay="false">
        <div class="again_diago">
          <div class="content">
            <div>“<span>{{parent_info.name}}</span>”已经接受您的邀请成为超级会员，恭喜您获得本次邀请返利，请您在12小时内选购<span>{{parent_info.amount}}元</span>及以上贵宾礼包来进行领取，否则系统将视为您主动放弃。</div>
            <!-- <div class="kefu">详情可咨询平台客服电话:<span>40000000</span></div> -->
          </div>
          <div class="action_btn">
            <span @click="closeTips">重新选择</span>
            <span @click="continueBuy">我知道了</span>
          </div>
        </div>
      </van-popup>
    </div>
    <div class="fiex_share" @click="share"></div>
  </div>
</template>

<script>
import Swipe from './component/swipe.vue'
import PrdItem from './component/prd_item.vue'
// import Path from '@/utils/path.js'
import Tool from '@/utils/tool.js'
import Domain from '@/utils/domain.js'

export default {
  props: ['page_type', 'invite_info', 'user_info'],
  components: { Swipe, PrdItem },
  data () {
    return {
      active: 1,
      first_show: false,
      last_show: false,
      prd_list: [],
      active_prd: '',
      parent_info: [],
      mit_tips: [
        '每家每户一年买两床冬被，两床夏被，三口之家，一年就省3468元'
      ],
      share_tips: [
        '多喜爱冬奢95白鹅绒被一件，分享赚1253元',
        '多喜爱全棉印花套件一件，分享赚113元 ',
        '小狗无线立式家用吸尘器一台，分享赚69.9元',
        '小熊家用迷你烤箱一台，分享赚35.9元'
      ]
    }
  },
  created () {
    this.getPrdList()
  },
  methods: {
    share () {
      var url = encodeURIComponent('pages/activity/join_vip/join_vip?invite=' + this.user_info.invite_id)
      var title = encodeURIComponent('倾情推荐！开启超级会员之旅，超值特权嗨不停。')
      var desc = encodeURIComponent('Hi，我是' + this.user_info.user_nickname + '分享一个正品购物平台给你')
      var imgurl = encodeURIComponent(Domain('/wechat/images/v4/share_vip.png'))
      let isClient = Tool.isClient()
      if (isClient) {
        window.location = 'yggshare://title=' + title + '&desc=' + desc + '&imgurl=' + imgurl + '&url=' + url
      } else {
        this.$toast('h5分享微信')
      }
    },
    getPrdList () {
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'product', params: { is_gift_bag: 1, pagesize: 100 }, method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            this.prd_list = resp.data.list
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    },
    showTips (e, prdInfo) {
      this.first_show = true
      this.active_prd = prdInfo
      this.parent_info = e.data
    },
    againOpenTips () {
      this.first_show = false
      this.last_show = true
    },
    closeTips () {
      this.first_show = false
      this.last_show = false
    },
    continueBuy () {
      let url = '/main/shopDetails'
      if (this.active_prd) {
        this.$router.push({ path: url,
          query: {
            item_id: this.active_prd.default_item_id
          }
        })
      }
    }
  }
}
</script>
